-------------Path configrations--------------------------------------
datapath = "data"
imagePath = "images"
fontPath = "fonts"
audioPath = "audio"
textPath = "texts"
levelPath = "levels"
scenePath = "scenes"
modulePath = "modules"

--
local function split(str, pat)
   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
	 table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end


function initLuaPath(paths)
    print(package.path)
	print("")
	local package_path = split(package.path, ";")
	local resultpaths = {}
	for i,v in ipairs(package_path) do
		local temp = string.sub(v, 1, -6)
		for n,p in ipairs(paths) do
			table.insert(resultpaths, string.format("%s%s/?.lua", temp,p))--temp .. p.."\\?.lua"
		end
	end
	package.path = string.format("%s;%s", package.path, table.concat(resultpaths, ";"))

	print (package.path)
end

local oldnewImageRect = display.newImageRect;
local oldnewImage = display.newImage;
local oldloadsound = audio.loadSound;
local oldloadstream = audio.loadStream;

display.newImageRect = function(file, w, h)
	return oldnewImageRect(string.format("%s/%s", imagePath, file),w,h)
end

display.newImage = function(file)
	return oldnewImage(string.format("%s/%s", imagePath, file))
end

audio.loadSound = function(file)
	--print(string.format("%s/%s", "images", file))
	return oldloadsound(string.format("%s/%s", audioPath, file))
end

audio.loadStream = function(file)
	--print(string.format("%s/%s", "images", file))
	return oldloadstream(string.format("%s/%s", audioPath, file))
end


initLuaPath{scenePath, modulePath, textPath}
